﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using SoccerEvaluator.Common;
using SoccerEvaluator.Business;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using System.Web.Script.Serialization;
using SoccerEvaluator.WebSite.App_Code;

namespace SoccerEvaluator.WebSite.ws
{
    /// <summary>
    /// Summary description for Loader
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class Loader : System.Web.Services.WebService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void GetResultInfo(int id)
        {
            SoccerEvaluatorModelContainer context = new SoccerEvaluatorModelContainer();

            Template t = context.Templates.FirstOrDefault(c => c.Id == id);

            TemplateInfo newTemplate = ObjectFactory.ToTemplateInfo(t);

            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();


            string val = serializer.Serialize(newTemplate);

            Context.Response.Write(val);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void ListProjects()
        {
            SoccerEvaluatorModelContainer context = new SoccerEvaluatorModelContainer();

            List<GroupInfo> groups = ObjectFactory.ToGroupsList(context.Groups.ToList());
            
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            string val = serializer.Serialize(groups);

            Context.Response.Write(val);
        }
    }
}
